/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controle;

import java.sql.SQLException;
import java.util.List;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
import modelo.Secretaria;
import persistencia.SecretariaDAO;

/**
 *
 * @author Soares
 */
@Named(value = "SecretariaMB")
@RequestScoped
public class SecretariaMB {
    
     private Secretaria secretaria;
    
    
    private SecretariaDAO secretariaDAO; 
    
   
    List<Secretaria> nomes;
    
    

   public SecretariaMB() throws SQLException {
        secretaria = new Secretaria();        
        secretariaDAO = new SecretariaDAO();
        nomes = secretariaDAO.getTodosSecretaria(SecretariaDAO.ORDEM_POR_ID);
    }

     public List<Secretaria> getNomes() {
        return nomes;
    }      
    

   
    public Secretaria getSecretaria() {
        return secretaria;
    }

    public void setSecretaria(Secretaria secretaria) {
        this.secretaria = secretaria;
    }     
    
   
    
   
    public void salvar() throws SQLException{
        if(this.secretaria.getId() == 0)
           secretariaDAO.salvar(secretaria);
        else
           secretariaDAO.alterar(secretaria);
           nomes = secretariaDAO.getTodosSecretaria(SecretariaDAO.ORDEM_POR_ID);
    }
    
   
    public void alterar(Secretaria nome){
        this.secretaria = nome;
    }
    
        
  
    public void excluir(Secretaria secretaria) throws SQLException{
        secretariaDAO.excluir(secretaria);
       
        nomes = secretariaDAO.getTodosSecretaria(SecretariaDAO.ORDEM_POR_ID);  
    }
    
   
    public void pesquisar() throws SQLException{
        secretaria = secretariaDAO.pesquisar(secretaria.getId());
    }
    
    
}
